/*
 * @Author: early-autumn
 * @Date: 2020-05-03 20:22:20
 * @LastEditors: early-autumn
 * @LastEditTime: 2020-05-05 19:25:07
 */
const cache = {}

export const DEFAULT_NAME = 'anonymous'

export function getId(name) {
  return `${window.location.pathname}::table::columns::${name}`
}

export function getValues(id) {
  if (!cache[id]) {
    const values = localStorage.getItem(id)
    cache[id] = values ? values.split(',') : values
  }
  return cache[id]
}

export function setValues(id, values) {
  cache[id] = values
  // 使用异步避免阻塞
  Promise.resolve().then(() => localStorage.setItem(id, values))
}
